//对axios进行封装
import axios from "axios";
//引入进度条
import nProgress from "nprogress";
import "nprogress/nprogress.css";

import store from '@/store'

//requests是一个axios实例
const requests = axios.create({
    //基础路径
    baseURL:'/api',
    //设置超时时间
    timeout:5000
});
//请求拦截器
requests.interceptors.request.use((config)=>{
    //config是配置对象
    if(store.state.detail.uuid_token){
        //请求头添加一个字段，要和后台老师商量
        config.headers.userTempId = store.state.detail.uuid_token
    };
    if(store.state.user.token){
        //请求头添加一个字段，要和后台老师商量
        config.headers.token = store.state.user.token
    };
    nProgress.start()
    return config
})
//响应拦截器
requests.interceptors.response.use((res)=>{
    nProgress.done()
    return res.data;
},(error)=>{
    //相应失败的回调
    
})
export default requests